module SOD
  
  class SelectionObserver < Sketchup::SelectionObserver
    
    def onSelectionBulkChange(selection)
      Plugin.model.active_bar.clear
      selection.each do |sel|
        if bar = Plugin.model.bars.find { |b| b.footprintID == sel.entityID }
          Plugin.model.active_bar.add bar.name
          #puts "Footprint of " + sel.belongsToBar + " added!" if sel.isFootprint?
        elsif sel.typename == "Group"
          if sel.name[0..2] == "Bar"
            Plugin.model.active_bar.add sel.name[0..3]
          end
        end
      end
      Plugin.model.active_bar.each { |b| print b.to_s + " -- " } if $debug
      
      if Plugin.dialogManager.active_interface(ProjectInfoInterface)
        Plugin.dialogManager.update(ProjectInfoInterface)
      end
      if Plugin.dialogManager.active_interface(StructureGeneratorInterface)
        Plugin.dialogManager.update(StructureGeneratorInterface)
      end
    end
    
    def onSelectionCleared(selection)
      Plugin.model.active_bar.clear
      # puts "Plugin.model.active_bar cleared" if $debug # only needed for checking. Otherwise it is displayed to often...
      
      if Plugin.dialogManager.active_interface(ProjectInfoInterface)
        Plugin.dialogManager.update(ProjectInfoInterface)
      end
      if Plugin.dialogManager.active_interface(StructureGeneratorInterface)
        Plugin.dialogManager.update(StructureGeneratorInterface)
      end
    end
    
  end
  
end
